<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/12
 * Time: 10:47
 */

//------------------------
//考勤
//-------------------------

namespace app\attendance\controller;
use app\attendance\Base;
use com\gdl\kq\dataobject\attendancegroup\AttendanceGroupDTO;
use com\gdl\kq\interfaces\AttendanceServiceClient;
use think\Config;
use think\Db;
use think\Loader;
use think\exception\HttpException;

class Attendance extends Base
{
    //添加考勤组
    public function addAttendanceGroup()
    {
        $title = $this->request->param('title') ? $this->request->param('title') : 0;//考勤组名称
        $plaformId = $this->request->param('plaformId') ? $this->request->param('plaformId') : [];//平台ID
        $setholidaysId = $this->request->param('setholidaysId') ? $this->request->param('setholidaysId') : [];//节假日设置
        $goDaysNum = $this->request->param('goDaysdata') ? $this->request->param('goDaysdata') : [];//一天内上下班的次数
        $unusualStatus = $this->request->param('unusualStatus') ? $this->request->param('unusualStatus') : [];//异常定义
        $coordinate = $this->request->param('coordinate') ? $this->request->param('coordinate') : [];//签到点坐标
        $groupMustUser = $this->request->param('groupMustUser') ? $this->request->param('groupMustUser') : [];//参与考勤人员
        $groupNotUser = $this->request->param('groupNotUser') ? $this->request->param('groupNotUser') : [];//无需考勤人员
        $approvalProcessOne = $this->request->param('approvalProcessOne') ? $this->request->param('approvalProcessOne') : 0;//请假审批流程方案ID
        $approvalProcessTwo = $this->request->param('approvalProcessTwo') ? $this->request->param('approvalProcessTwo') : 0;//外出审批流程方案ID
        $approvalProcessThree = $this->request->param('approvalProcessThree') ? $this->request->param('approvalProcessThree') : 0;//补卡审批流程方案ID
        $offDutyOut = $this->request->param('offDutyOut') ? $this->request->param('offDutyOut') : 1;// 下班是否需要打卡 1打卡 2不打卡
        $faceStatus = $this->request->param('faceStatus') ? $this->request->param('faceStatus') : 1;// 是否开启人脸 1开启 2不开启
        $trackLocation = $this->request->param('trackLocation') ? $this->request->param('trackLocation') : 1;// 1不开启轨迹定位 2开启轨迹定位
        $adminuserid = $this->request->param('adminuserid') ? $this->request->param('adminuserid') : 0;
        $reg = $this->request->param('reg') ? getStr($this->request->param('reg')) : '';

        if (empty($title) || empty($setholidaysId)|| empty($plaformId) || empty($goDaysNum) || empty($groupMustUser)|| empty($groupNotUser)){
            $data = ['msg'=>'参数错误','code'=>'400','data'=>[]];
            return json_encode($data);
        }
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk','gdlAgkSdk'));
            $api = new AttendanceServiceClient(NULL);
            \ApiClient::build($api);
            $data = [
                'title'=>$title,
                '$setholidaysId'=>$setholidaysId,
                'plaformId'=>$plaformId,
                'goDaysNum'=>json_encode($goDaysNum),
                'unusualStatus'=>json_encode($unusualStatus),
                'coordinate'=>json_encode($coordinate),
                'groupNotUser'=>json_encode($groupNotUser),
                'groupMustUser'=>json_encode($groupMustUser),
                'approvalProcessOne'=>$approvalProcessOne,
                'approvalProcessTwo'=>$approvalProcessTwo,
                'approvalProcessThree'=>$approvalProcessThree,
                'offDutyOut'=>$offDutyOut,
                'faceStatus'=>$faceStatus,
                'trackLocation'=>$trackLocation,
                'adminuserid'=>$adminuserid,
                'reg'=>$reg,
            ];
            $AttendanceGroupDTO = new AttendanceGroupDTO();
            $AttendanceGroupDTO->data	= $data;
//            $engprojectDo->userid	= $adminuserid;
//            $engprojectDo->reg		= $reg;
            $result = $api->addAttendanceGroup($AttendanceGroupDTO);
var_dump($result);die;
//            if($result->code){
            /*****测试原型*****/

//            }
            //checkstate 1是选中 0是未选中
            $data =  ['msg'=>'获取成功','code'=>'200','data'=>$plaform];
        } catch (Exception $ex) {
            $data = ['msg'=>'获取失败','code'=>'400','data'=>[]];
        }
        return json_encode($data);

    }
    //考勤组列表
    public function getAttendanceGroupList()
    {
        $unitid = $this->request->param('unitid') ? $this->request->param('unitid/d') : 0;//部门id  现在是用户传 改完后直接查询管理员部门完成
        $adminuserid = $this->request->param('adminuserid') ? $this->request->param('adminuserid') : 0;
        $reg = $this->request->param('reg') ? getStr($this->request->param('reg')) : '';
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk','gdlAgkSdk'));
            //$api = new UnitsServiceClient(NULL);
            //\ApiClient::build($api);
            $plaform = [];
            //$engprojectDo = new UnitsDTO();
//            $engprojectDo->unitid	= $unitid;
//            $engprojectDo->userid	= $adminuserid;
//            $engprojectDo->reg		= $reg;
//            $result = $api->lookeOver($engprojectDo);

//            if($result->code){
                /*****测试原型*****/

//            }
            //checkstate 1是选中 0是未选中
            $data =  ['msg'=>'获取成功','code'=>'200','data'=>$plaform];
        } catch (Exception $ex) {
            $data = ['msg'=>'获取失败','code'=>'400','data'=>[]];
        }
        return json_encode($data);

    }

}